# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=openapi-generator
pkgver=6.5.0
pkgrel=1
pkgdesc="Generation of API client libraries, server stubs, documentation and configuration"
arch=(any)
url="https://github.com/openapitools/openapi-generator/"
license=(Apache)
depends=(
  bash
  java-runtime=8)
makedepends=(
  maven
  java-environment=8
  strip-nondeterminism
)
source=(
  $url/archive/v$pkgver/$pkgname-v$pkgver.tar.gz
  $pkgname.sh
)
sha512sums=('d29471abeac05bc3ef6e1ce2ec27f781cea91020e32ab3aaf0bbee6e57dc222341094ca8f6d7b074a97abb2f3fbc26fce9fbe11b1a0940c80fc0d3dfa07620cd'
            '0b81955e2da12182b70366c4d8ff48d970a0edee6242a13dc657879b2e1c15205a2bfa01cbef51dd86d90e1176569a211b704d30d19b529e15ead825a89a4e9c')
b2sums=('7bf87c7ae7bb5b1a72eb6f2959bd402cdb16421b6be5b5005206fa855b6ffbba1259813187c181efd224909e9baa0173762669f6b6c264f8f12d058b98dc455e'
        'd2f38df8fd23a32e95e9e09624283ca4927dce8cf6dbdbfc11547396ae2bd9c6c1ff65082447f1e30caba3654fd6e50558272d524242ca6727df7024729a1123')

build() {
  cd $pkgname-$pkgver
  mvn clean install
  # Timestamps in JAR files generated by Maven do not honour SOURCE_DATE_EPOCH
  # (https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=74682318)
  find . -type f -iname "*.jar" -exec strip-nondeterminism --timestamp "$SOURCE_DATE_EPOCH" {} \;
}

package() {
  install -vDm 644 $pkgname-$pkgver/modules/$pkgname-cli/target/openapi-generator-cli.jar -t "$pkgdir/usr/share/java/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/scripts/$pkgname-cli-completion.bash "$pkgdir/usr/share/bash/bash-completion/completions/openapi-generator"
  install -vDm 755 $pkgname.sh "$pkgdir/usr/bin/$pkgname"
  ln -svf "$pkgname" "$pkgdir/usr/bin/$pkgname-cli"
}
